package com.yootk.config;

import com.yootk.filter.MessageFilter;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.servlet.Filter;

/**
 * 过滤器配置
 */
@Configuration
public class WebFilterConfig {

    @Bean
    public FilterRegistrationBean getMessageFilterRegistration() {
        FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean();
        filterRegistrationBean.setFilter(messageFilter());      // 添加过滤器
        filterRegistrationBean.setName("messageFilter");        // 过滤器名称
        filterRegistrationBean.addUrlPatterns("/message/*");    // 拦截路径
        filterRegistrationBean.setOrder(5);                     // 设置顺序
        return filterRegistrationBean;
    }

    @Bean
    public Filter messageFilter() {     // 过滤器执行类
        return new MessageFilter();
    }
}
